[(x << 1) + 2, (x << 1) + 3] is a binary tree


From the post $$x + 1 \ \text{is a list}$$ I bring to you the binary tree. If details are needed please refer to this. I had to modify slightly the function to take care of vector outputs.

  
from numbers import Real

def build_domain(min_d: Real, max_d: Real, N: int): return np.linspace(min_d, max_d, N)

def closest(fx, D: np.ndarray) -> int: return np.argmin(np.abs(fx-D))

def build_graph(min_d: Real, max_d: Real, N: int, fn: Callable[[Real], Real | list[Real] | np.ndarray]) -> nx.Graph:
    D = build_domain(min_d, max_d, N)
    G = nx.Graph()
    for i, x in enumerate(D): G.add_node(i, x=x)
    for i, x in enumerate(D):
        if i == N-1: break
        connected_to = fn(x)
        if isinstance(connected_to, (list, np.ndarray)):
            for y in connected_to:
                if i == y: continue
                G.add_edge(i, y)
        elif isinstance(connected_to, Real)
            if i == y: continue
            G.add_edge(i, y)
    return G

  

with this setting $$f(x) = \begin{pmatrix} x \ll 1 + 2 & x \ll 1 + 3 \end{pmatrix}$$ gives birth to a tree